package com.example.lynandroid.fragment

import android.content.Context
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import com.example.lynandroid.enum.LifeType
import com.example.lynandroid.lifeLog

open class BaseFragment(resId: Int) : Fragment(resId) {
    open fun getFragmentName(): String? {
        return null
    }

    override fun onAttach(context: Context) {
        super.onAttach(context)
        log(LifeType.Attach)
    }


    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        log(LifeType.CreateView)


        return super.onCreateView(inflater, container, savedInstanceState)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        log(LifeType.ViewCreated)
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        log(LifeType.Create)
    }

    override fun onStart() {
        super.onStart()
        log(LifeType.Start)
    }

    override fun onResume() {
        super.onResume()
        log(LifeType.Resume)
    }


    override fun onPause() {
        super.onPause()
        log(LifeType.Pause)
    }

    override fun onStop() {
        super.onStop()
        log(LifeType.Stop)
    }

    override fun onDestroyView() {
        super.onDestroyView()
        log(LifeType.DestroyView)
    }

    override fun onDestroy() {
        super.onDestroy()
        log(LifeType.Destroy)
    }

    override fun onDetach() {
        super.onDetach()
        log(LifeType.Detach)
    }

    private fun log(lifeType: LifeType) {
        lifeLog(getFragmentName(), lifeType)
    }
}